#%% 指标约减 对原数据进行标准化
import pandas as pd

#%% 读取数据
traindata_path=r'./data/trainset.xlsx'
traindata = pd.read_excel(traindata_path)
testdata_path = r'./data/testset.xlsx'
testdata = pd.read_excel(testdata_path)
indexColumns=traindata.columns

#%% 对训练集和测试集标准化
trainIndex = traindata[indexColumns]
testIndex = testdata[indexColumns]

x_train=trainIndex.iloc[:,:-1]
y_train=trainIndex.iloc[:,-1]
x_test=testIndex.iloc[:,:-1]
y_test=testIndex.iloc[:,-1]

#%%
from sklearn.preprocessing import StandardScaler
import numpy as np 
scaler = StandardScaler()
scaler.fit(x_train)
trainIndexStand_np = scaler.transform(x_train)
testIndexStand_np = scaler.transform(x_test)

xTrainScaler_df = pd.DataFrame(data=trainIndexStand_np, columns=indexColumns[:-1])
xTestScaler_df = pd.DataFrame(data=testIndexStand_np, columns=indexColumns[:-1])

trainDataStand = pd.concat([xTrainScaler_df,y_train], axis=1)
testDataStand = pd.concat([xTestScaler_df,y_test], axis=1)

trainDataStand.to_excel('./data/trainStand.xlsx',index=False)
testDataStand.to_excel('./data/testStand.xlsx',index=False)
